{extend name="Public/layout2.html"}
{block name='body'}
<blockquote class="layui-elem-quote">
    <span class="layui-breadcrumb">
  					<a href="../">首页</a>
  					<a><cite>工单列表</cite></a>
					</span>
</blockquote>
<fieldset class="layui-elem-field layui-field-title">
    <legend>工单列表</legend>
</fieldset>
<div class="div" style="margin:0px 20px;padding:10px 2px;width: 90%;background-color: #eeeeee">

    <div class="layui-form-pane" style="margin-top: 15px;">

        <div class="layui-form-item">

            <label class="layui-form-label">范围选择</label>
            <div class="layui-input-inline">
                <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
            </div>
            <div class="layui-input-inline">
                <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
            </div>
            <button class="layui-btn"onclick="serbytime()" ><i class="layui-icon">&#xe615; </i>搜索</button>
            <button class="layui-btn"onclick="refreshTable()" ><i class="layui-icon">&#xe63d; </i>刷新</button>
            <button class="layui-btn" onclick="addlayer()"><i class="layui-icon">&#xe609; </i>新增你说好不好</button>
        </div>
    </div>
</div>

<div style="padding: 20px;">

    <table class="layui-table" id="table1">

        <thead>
        <tr>
            <th>id</th>
            <th>工作内容</th>
            <th>站点</th>
            <th>人员</th>
            <th>时间</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>

    </table>
</div>


{/block}
{block name="jslink"}
{__block__}
<script type="text/javascript">

    function addlayer(id) {
        var str2="";
        if (id) {
            str2 = "?id=" + id;
        }
        var str1 = "{:url('index/gsrecord/addgs')}";
        var addgs = layer.open({
            area: ['1200px', '600px'],
            type: 2,
            content: str1 + str2
        });

    }

    /*

     */
    function refreshTable() {
        table.settings()[0].ajax.data=null;
        table.ajax.reload(null, false);
    }

    /**
     * 根据id删除gsrecord
     * @param id
     */
    function del(id) {
        var url = "{:url('index/gsrecord/deletebyid')}";
        var data = {
            id: id
        };


        $.post(url, data, function (data) {
            layer.msg(data.msg);
            refreshTable();
        })

    }

    /**
     *
     * @param id
     */
    function pendrecord(id) {
        var url = "{:url('index/gsrecord/pendbyid')}";
        var data = {
            id: id
        };


        $.post(url, data, function (data) {
            layer.msg(data.msg);
            refreshTable();
        })
    }

    function modifyrecord(id) {
//        var url = "{:url('index/gsrecord/addgs')}";
//        var data = {
//            id: id
//        };
//
//
//        $.post(url, data, function(data) {
//            layer.msg(data.msg);
//            refreshTable();
//        })
        addlayer(id);
    }
</script>
<script type="text/javascript">


    var table = null;


    function createTop() {
        var str = '<div class="layui-btn-group">' +

            '    <label  style="width: 160px" class="layui-form-label">范围选择</label>' +
            '    <div class="layui-input-inline">' +
            '      <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">' +
            '    </div>' +
            '    <div class="layui-input-inline">' +
            '      <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">' +
            '    </div>' + '  <button class="layui-btn layui-btn-small"> <i class="layui-icon">&#x1002; </i>刷新  </button>';


        $("div.dt_top").html(str);
    }


    function ser(str) {
        var ddd = $("#table1_filter input");
        if (!(ddd.val().indexOf(str) >= 0)) {
            ddd.val(ddd.val() + " " + str);
        }
        //我把这个数值直接输入到过滤框中,无效

        table.search(ddd.val()).draw();
    }

    /**
     *
     */
    function serbytime() {
        var stime=$('#LAY_demorange_s').val();
        var dtime=$('#LAY_demorange_e').val();
        var param2 = {
            "stime": stime,
            "dtime": dtime
        };
        table.settings()[0].ajax.data=param2;
        table.ajax.reload();
    }

    $(function () {


            table = $('#table1').DataTable({
                "autoWidth": false,
                "order": [],
                "ajax": {
                    "url": "{:url('index/gsrecord/getlist')}",

                },
                'dom': '<i<"dt_top">f>rtlp<"clear">',
                'columnDefs': [{
                    'targets': [2, 3],
                    "defaultContent": "无",
                    'render': function (data, type, full, meta) {
                        if (type === 'display') {
                            var result = data.split(',');
                            var str1 = '<span>';
                            for (var i = 0; i < result.length; i++) {
                                var id = '"' + result[i] + '"';
                                var fun2 = "ser(" + id + ")";
                                str1 += '<a class="" onclick=' + fun2 + ' href="#">' + result[i] + '</a>&nbsp&nbsp';
                            }
                            str1 += '</span>';
                            return str1;
                        }
                        return data;

                    }
                },
                    {
                        'targets': -1,
                        'data': null,
                        "render": function (data, type, row, meta) {
                            var ss = data;
                            var id = '"' + row.id + '"';
                            var fun2 = "del(" + id + ")";
                            var fun3 = "pendrecord(" + id + ")";
                            var fun4 = "modifyrecord(" + id + ")";
                            return '<div class="layui-btn-group">' +
                                '  <button class="layui-btn-small layui-btn  layui-btn-danger" onclick=' + fun2 + ' > <i class="layui-icon">&#xe640;</i> 删除</button>' +
                                '  <button class="layui-btn-small layui-btn" onclick=' + fun3 + ' > <i class="layui-icon">&#xe618;</i> 审核</button>' +
                                '  <button class="layui-btn-small layui-btn layui-btn-normal" onclick=' + fun4 + ' > <i class="layui-icon">&#xe642;</i> 修改</button>' +
                                '</div>';

                        }

                    },
                    {
                        'targets': -2,
                        "render": function (data, type, row, meta) {
                            return data == 1 ? '<i class="layui-icon" style="color:green;font-weight: bolder">&#xe605;</i>' : '<i class="layui-icon" style="color: red;font-weight: bolder">&#x1006;</i> ';
                        }
                    }
                ],
                "columns": [
                    {"data": "id", "width": "50px"},
                    {"data": "content"},
                    {"data": "name", "width": "70px"},
                    {"data": 'members[,].name', "width": "200px"},
                    {"data": 'starttime', "width": "200px"},
                    {"data": 'pend', "width": "70px"},
                    {"data": null, "width": "260px"},
                ],
            });

//createTop();
        }
    )
</script>
<script>
    $(function () {

        var laydate = layui.laydate;

        var start = {
            format: 'YYYY-MM-DD ', //日期格式
            max: '2099-06-16 23:59:59'

            , istoday: false
            , choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };

        var end = {
            format: 'YYYY-MM-DD', //日期格式
            min: laydate.now()

            , max: '2099-06-16 23:59:59'
            , istoday: false
            , choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };

        document.getElementById('LAY_demorange_s').onclick = function () {
            start.elem = this;
            laydate(start);
        };
        document.getElementById('LAY_demorange_e').onclick = function () {
            end.elem = this;
            laydate(end);
        }
    });


</script>
{/block}
